<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
    
    protected function _initDb(){
        $optionResources = $this->getOption('resources');
        $dbResources = $optionResources['db'];
        
        $adapter = $dbResources['adapter'];
        $params = $dbResources['params'];
        
        $adapter2 = $dbResources['adapter2'];
        $params2 = $dbResources['params2'];
        
        $db = Zend_Db::factory($adapter, $params);
        $db2 = Zend_Db::factory($adapter2, $params2);
        
        $db->setFetchMode(Zend_Db::FETCH_OBJ);
        $db->query("SET NAMES 'utf8'");
        $db->query("SET CHARACTER SET 'utf8'");
        
        $db2->setFetchMode(Zend_Db::FETCH_OBJ);
        $db2->query("SET NAMES 'utf8'");
        $db2->query("SET CHARACTER SET 'utf8'");
        
        Zend_Registry::set('db', $db);
        Zend_Registry::set('db2', $db2);
        Zend_Db_Table::setDefaultAdapter($db);
    }
    
    protected function _initDateTime(){
        $timezone = date_default_timezone_set('Asia/Ho_Chi_Minh');
        $formatInsert = "yyyy-MM-dd HH:mm:ss";
        Zend_Registry::set('date_format_insert', $formatInsert);
        
        return $timezone;
    }
    
    protected function _initLocale(){
        setlocale(LC_ALL, "vi_VN.UTF-8");
    	$locale = "vi";
        Zend_Registry::set('locale', $locale);
        
        $file = APPLICATION_PATH . "/languages/validate/$locale/lang.csv";
        
        $option = array('adapter' => 'csv',
                        'content' => $file,
                        'locale' => $locale,
                        'delimiter' => '=');
                        
    	$translate = new Zend_Translate($option);
        $translate->setLocale($locale);
        
        Zend_Validate_Abstract::setDefaultTranslator($translate);
        
        return $locale;
    }
    
    protected function _initFrontController(){
        $front = Zend_Controller_Front::getInstance();
        $front->addModuleDirectory(APPLICATION_PATH . "/modules");
        $front->setDefaultModule('default');
        
        $error = new Zend_Controller_Plugin_ErrorHandler(array('module' => 'admin', 'controller' => 'error', 'action' => 'index'));
        
        //$front->registerPlugin($error);
        $front->registerPlugin(new Zenddn_Plugin_Permission());
        $front->registerPlugin(new Zenddn_Plugin_Privileges());
        $front->registerPlugin(new Zenddn_Plugin_Language());
        
        return $front;
    }
}